package main;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Vector;
import java.util.Enumeration;

public class PokemonTeam {

    private Vector _listPokemon = new Vector();
    private Vector _listPokemonLeft = new Vector();
    private boolean _isInControl;
    private int _color;

    public PokemonTeam() {
    }
    
    public void setColor(int color)
    {
        _color = color;
        for(int i=0;i<_listPokemon.size();i++)
        {
            ((Pokemon)_listPokemon.elementAt(i)).setColor(_color);
        }
    }

    public void add(Pokemon pokemon) {
        pokemon.setColor(_color);
        _listPokemon.addElement(pokemon);

    }

    public int count() {
        return _listPokemon.size();
    }

    public int countActive() {
        return _listPokemonLeft.size();
    }

    public Pokemon getActivePokemonAt(int i) {
        return (Pokemon) _listPokemonLeft.elementAt(i);
    }

    public Pokemon getPokemonAt(int i) {
        return (Pokemon) _listPokemon.elementAt(i);
    }

    public void buildPokemonControlList() {

        _listPokemonLeft.removeAllElements();
        for (int i = 0; i < _listPokemon.size(); i++) {
            if (((Pokemon) _listPokemon.elementAt(i)).getHp() > 0) {
                boolean flag = true;

                for (int j = 0; j < _listPokemonLeft.size(); j++) {
                    if (((Pokemon) _listPokemon.elementAt(i)).getSpeed() > ((Pokemon) _listPokemonLeft.elementAt(j)).getSpeed()) {
                        _listPokemonLeft.insertElementAt(_listPokemon.elementAt(i), j);
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    _listPokemonLeft.addElement(_listPokemon.elementAt(i));
                }
            }
        }
        //System.out.print(_listPokemonLeft.size());
    }

    public Pokemon getPokemon() {
        if (_listPokemonLeft.isEmpty()) {
            return null;
        }
        while (((Pokemon) _listPokemonLeft.firstElement()).getHp() <= 0) {
            _listPokemonLeft.removeElementAt(0);
            if (_listPokemonLeft.isEmpty()) {
                return null;
            }
        }

        return (Pokemon) _listPokemonLeft.firstElement();
    }

    public Pokemon removePokemon() {
        if (_listPokemonLeft.isEmpty()) {
            return null;
        }
        Pokemon firstPokemon = (Pokemon) _listPokemonLeft.firstElement();
        _listPokemonLeft.removeElementAt(0);
        return firstPokemon;
    }
}
